#include <iostream>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <unordered_set>
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int N=1e7+3;
int prime[N];
int v[N];
int m=0;
void get_prime(int n)
{
	
	for (int i = 2; i<=n; i++) {
	if (v[i] == 0) { 
		v[i] = i;
		prime[++m] = i;
	}
	for (int j = 1; j <= m; j++) {
		if (prime[j] > v[i] || prime[j] > n/i) break;
		v[i*prime[j]] = prime[j];
	}
}

}
int check(int x)
{
	vector<int> a;
	while(x)
	{
		a.push_back(x%10);
		x/=10;
	}
	int l=0,r=a.size()-1;
	while(l<r)
	{
		if(a[l]!=a[r]) return 0;
		l++,r--;
	}
	return 1;
}
int main()
{
	IOS;
	int l,r;
	cin>>l>>r;
	if(r>1e7) r=1e7;
	get_prime(r);
	for(int i=3;i<=m;i++)
	{
		if(prime[i]<l) continue;
		if(check(prime[i])) cout<<prime[i]<<endl;
	}

	return 0;
}

